<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class La_Controller extends CI_Controller
{
	var $data;
	function La_Controller()
	{
		parent::__construct();
		$this->load->library('authorize');
		$this->load->helper(array("form", "security", 'url', 'laoa'));
		$this->load->model(array('Setting_model', 'Forbidden_ip_model'));
		
		$this->load->driver('cache');
		$settings = $this->cache->file->get("settings");
		if (empty($settings)) {
			$settings = $this->Setting_model->find_all();
			$this->cache->file->save('settings', $settings, 3600);
		}
		$forbidden_ips = $this->cache->file->get("forbidden_ips");
		if (empty($forbidden_ips)) {
			$forbidden_ips = $this->Forbidden_ip_model->find_all_ips();
			$this->cache->file->save('forbidden_ips', $forbidden_ips, 3600);
		}
		if(!empty($settings['close_website'])  && $settings['close_website'] === 'yes' && $this->uri->segment(1) != 'admin' && $this->uri->segment(1) != 'console') {
			redirect('/errors/closed');
			exit(0);
		}
		$current_ip = $this->input->ip_address();
		if(!empty($forbidden_ips) && in_array($current_ip, $forbidden_ips) && $this->uri->segment(1) != 'admin' && $this->uri->segment(1) != 'console') {
			redirect('/errors/forbidden');
			exit(0);
		}
		
	}
	
	function page_title($title) {
		$this->data['page_title'] = $title;
	}

}